<%-------------------------------------------------------------------
 * 页面名称：batchPeerAccountInput.jsp
 * 功能描述：批量支付选择支付对象弹出页面
 * Action: 
 *
 *-------------------------------------------------------------------
--%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-bean.tld" prefix="bean"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ad" uri="agiledata"%>
<%
    String path = request.getContextPath();
%>
<link href="<%=path%>/css/style.css" rel="stylesheet" type="text/css" />
<link href="<%=path%>/css/font.css" rel="stylesheet" type="text/css" />
<link href="<%=path%>/css/newstyle.css" rel="stylesheet" type="text/css" />
<link href="<%=path%>/css/common.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.box {width:100%;margin:auto;}
.off {margin-left:3px;line-height:34px;float:left;width:93px;height:34px;color:#003365;font-size:14px;font-weight:bold;text-align:center;background-image:url(<%=path%>/images/p_on.gif);cursor:pointer;}
.on {margin-left:3px;line-height:34px;float:left;width:93px;height:34px;color:#B77443;font-size:14px;font-weight:bold;text-align:center;background-image:url(<%=path%>/images/p_hover.gif);}
.tab {width:100%;margin:auto;float:left;background:url(<%=path%>/images/apply_bg02.gif) top left no-repeat}
-->
</style>
<script type='text/javascript' src='<%=path%>/js/vnv/commonForManage.js'></script>
<script type='text/javascript' src='<%=path%>/dwr/util.js'></script>
<script type='text/javascript' src='<%=path%>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=path%>/dwr/interface/transactionFacade.js'></script>
<script type="text/javascript">
function toChangeType(type){
    window.setTimeout("changeType('"+type+"')",100);
}
function changeType(type){
    var count = parseInt(document.getElementById("count").innerText);
    if(count>0){
        if(!confirm("改变交易对方账户类型将使得已经设置的账户和金额被清除，您确实要改变吗？")){
            return;
        }
    }
    document.forms[0].type.value = type;
    document.forms[0].submit();
}
function selectAll(selectAllBox){
    var selected = selectAllBox.checked;
    var ids = document.getElementsByName("id");
    for(var i=0;i<ids.length;i++){
        if(ids[i].checked!=selected){
            ids[i].click();
        }
    }
}
function activateAmount(id){
    var amount = document.getElementById("amount_"+id);
    amount.disabled = false;
    //amount.className = "";
}
function inactivateAmount(id){
    var amount = document.getElementById("amount_"+id);
    amount.value = "0.00";
    amount.disabled = true;
    //amount.className = "input-disabled";
    var fee = document.getElementById("fee_"+id);
    fee.innerText = "0.00";
    transactionFacade.removePeerAccountAmount(id,setTotal);
}
function selectPeerAccount(selectBox){
    var selected = selectBox.checked;
    var id = selectBox.value;
    if(selected){ //选择
        activateAmount(id);
    }else{ //不选择
        inactivateAmount(id);
    }
}
function changeAmount(amountObj){
    var id = amountObj.id.substring("amount_".length);
    if(!isNumberFloat(amountObj.value)){
        alert("您输入的金额格式错误，请重新输入！");
        amountObj.value = "0.00";
        amountObj.focus();
        return;
    }
    var amount = parseFloat(amountObj.value);
    amountObj.value = formatAmount(amount,2,"");
    amount = parseFloat(amountObj.value);
    if(amount<=0){
        if(confirm("金额必须在精确到分之后大于0，点击\"确定\"重新输入金额，点击\"取消\"不再选择该账户")){
            amountObj.value = "0.00";
            amountObj.focus();
        }else{
            var idObj = document.getElementById("id_"+id);
            idObj.click();
        }
    }else{
       transactionFacade.savePeerAccountAmount(id,amount,setPeerAccountAmount);
    }
}
function setPeerAccountAmount(peerAccountAmount) {
    var id = peerAccountAmount.id;
    document.getElementById("fee_"+id).innerText = formatAmount(peerAccountAmount.fee);
    transactionFacade.getBatchPeerAccount(setTotal);
}
var globalBatchPeerAccount = null;
function setTotal(batchPeerAccount){
    globalBatchPeerAccount = batchPeerAccount;
    document.getElementById("count").innerText = batchPeerAccount.count;
    document.getElementById("total").innerText = formatAmount(batchPeerAccount.totalAmountWithFee);
    document.getElementById("totalAmount").innerText = formatAmount(batchPeerAccount.totalAmountWithoutFee);
    document.getElementById("totalFee").innerText = formatAmount(batchPeerAccount.totalFee);
}
function closePage(){
    if(globalBatchPeerAccount!=null && globalBatchPeerAccount!=undefined){
        returnValue(globalBatchPeerAccount);
    }else{
        transactionFacade.getBatchPeerAccount(returnValue);
    }
}
function returnValue(batchPeerAccount){
    window.parent.closeLayer(batchPeerAccount,document.forms[0].type.value);
}
</script>
<html:form action="inputBatchPeerAccount">
<html:hidden property="type"/>
<html:hidden property="subAccountId"/>
<table border="0" cellpadding="0" cellspacing="0" >
<tr><td>
<div class="tab">
<logic:equal name="batchPeerAccount" property="innerBatchPeerAccount" value="true">
<div class="on">支付账户</div>
<div class="off" onClick="toChangeType('bank')">银行账户</div>
</logic:equal>
<logic:equal name="batchPeerAccount" property="innerBatchPeerAccount" value="false">
<div class="off" onClick="toChangeType('inner')">支付账户</div>
<div class="on">银行账户</div>
</logic:equal>
</div>
</td></tr>
<tr><td>
<table border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td bgcolor="#FFFFFF">
   <logic:equal name="batchPeerAccount" property="innerBatchPeerAccount" value="true">
    <table width="100%" border="0" cellspacing="1" cellpadding="5">
      <tr>
        <th height="25" bgcolor="#BFDBF3"><input type="checkbox" name="selectAllBox" style="border:0" alt="全选" onclick="selectAll(this)" /></th>
        <th bgcolor="#BFDBF3">账户名称</th>
        <th bgcolor="#BFDBF3">email</th>
        <th bgcolor="#BFDBF3">手机号码</th>
        <th bgcolor="#BFDBF3">金额（元）</th>
        <th bgcolor="#BFDBF3">手续费（元）</th>
      </tr>
      <c:forEach var="record" items="${result.data}" varStatus="status">
      <tr align="center">
        <td bgcolor="#F0F9FE" nowrap><input type="checkbox" style="border:0" name="id" onclick="selectPeerAccount(this)" id="id_<bean:write name="record" property="id" />" value="<bean:write name="record" property="id" />" <logic:equal name="record" property="selected" value="true">checked</logic:equal> /></td>
        <td bgcolor="#F0F9FE" nowrap><bean:write name="record" property="name" /></td>
        <td bgcolor="#F0F9FE" nowrap><bean:write name="record" property="email" /></td>
        <td bgcolor="#F0F9FE" nowrap><bean:write name="record" property="mobile" /></td>
        <td bgcolor="#F0F9FE" nowrap><input id="amount_<bean:write name="record" property="id" />" type="text" size="10" maxlength="12" value="<bean:write name="record" property="amount" format="#0.00" />" onblur="changeAmount(this)" <logic:equal name="record" property="selected" value="false">disabled</logic:equal>/></td>
        <td bgcolor="#F0F9FE" nowrap><span id="fee_<bean:write name="record" property="id" />"><ad:FormatPrase><bean:write name="record" property="fee" /></ad:FormatPrase></span></td>
      </tr>
      </c:forEach>
     </table>
      </logic:equal>
      <logic:equal name="batchPeerAccount" property="innerBatchPeerAccount" value="false">
      <table width="100%" border="0" cellspacing="1" cellpadding="5">
      <tr>
        <th height="25" bgcolor="#BFDBF3"><input type="checkbox" name="selectAllBox" alt="全选" onclick="selectAll(this)"  style="border:0"/></th>
        <th bgcolor="#BFDBF3">姓名</th>
        <th bgcolor="#BFDBF3">银行账号</th>
        <th bgcolor="#BFDBF3">银行名称</th>
        <th bgcolor="#BFDBF3">金额（元）</th>
        <th bgcolor="#BFDBF3">手续费（元）</th>
      </tr>
      <c:forEach var="record" items="${result.data}" varStatus="status">
      <tr align="center">
        <td bgcolor="#F0F9FE" nowrap><input type="checkbox" name="id" style="border:0" onclick="selectPeerAccount(this)" id="id_<bean:write name="record" property="id" />" value="<bean:write name="record" property="id" />" <logic:equal name="record" property="selected" value="true">checked</logic:equal> /></td>
        <td bgcolor="#F0F9FE" nowrap><bean:write name="record" property="peerName" /></td>
        <td bgcolor="#F0F9FE" nowrap><bean:write name="record" property="cardNo" /></td>
        <td bgcolor="#F0F9FE" nowrap><bean:write name="record" property="bankName" /></td>
        <td bgcolor="#F0F9FE" nowrap><input id="amount_<bean:write name="record" property="id" />" type="text" size="10" maxlength="12" value="<bean:write name="record" property="amount" format="#0.00" />" onblur="changeAmount(this)" <logic:equal name="record" property="selected" value="false">disabled</logic:equal>/></td>
        <td bgcolor="#F0F9FE" nowrap><span id="fee_<bean:write name="record" property="id" />"><ad:FormatPrase><bean:write name="record" property="fee" /></ad:FormatPrase></span></td>
      </tr>
      </c:forEach>
      </table>
      </logic:equal>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr height="25">
        <td align="center" class="font_blue">
        <ad:PageBean name="result"></ad:PageBean>
        </td>
      </tr>
      </table>
      <table width="100%" border="0" cellspacing="1" cellpadding="5" >
      <tr height="28" align="center">
        <td bgcolor="#F0F9FE" nowrap align="right" colspan="2">合计：</td>
        <td bgcolor="#F0F9FE" nowrap colspan="2">
              共 <strong><span id="count" style="color:#FF0000;font-size:12px;"><bean:write name="batchPeerAccount" property="count"/></span></strong> 笔<strong>
            <span id="total" style="color:#FF0000;font-size:12px;"><ad:FormatPrase><bean:write name="batchPeerAccount" property="totalAmountWithFee"/></ad:FormatPrase></span></strong> 元
        </td>
        <td bgcolor="#F0F9FE" nowrap>
            <strong><span id="totalAmount"><ad:FormatPrase><bean:write name="batchPeerAccount" property="totalAmountWithoutFee"/></ad:FormatPrase></span></strong>
        </td>
        <td bgcolor="#F0F9FE" nowrap>
            <strong><span id="totalFee"><ad:FormatPrase><bean:write name="batchPeerAccount" property="totalFee"/></ad:FormatPrase></span></strong>
        </td>
      </tr>
      <tr height="28" align="center">
        <td bgcolor="#F0F9FE" nowrap align="right" colspan="2">手续费收取方法：</td>
        <td bgcolor="#F0F9FE" nowrap colspan="4"><bean:write name="feeMode"/></td>
      </tr>
      <tr height="28" align="center">
        <td bgcolor="#F0F9FE" nowrap align="right" colspan="2">付款子账户：</td>
        <td bgcolor="#F0F9FE" nowrap><bean:write name="subAccount" property="accountName"/></td>
        <td bgcolor="#F0F9FE" nowrap align="right">当前余额（元）：</td>
        <td bgcolor="#F0F9FE" nowrap colspan="2"><strong><ad:FormatPrase><bean:write name="subAccount" property="accountBalance.balance" /></ad:FormatPrase></strong></td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</td></tr>
<tr><td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="41" align="right"><input type="button" value="关 闭" class="graybutton_style" onclick="window.setTimeout('closePage()',300)" />
      &nbsp;&nbsp;&nbsp;&nbsp;</td>
  </tr>
</table>
</td></tr>
</table>
</html:form>
<script type="text/javascript">
window.parent.showLayer(window);
</script>